<template>
    <div>
        <h3 style="text-align:center;color:white;line-height:50px;margin-right:100px;float:left;">
            逛逛后台管理系统
        </h3>
        <!-- <el-breadcrumb>
            <el-breadcrumb-item v-for="item in tags" :key="item.path" :to="{ path: item.path }">{{item.label}}</el-breadcrumb-item>
        </el-breadcrumb> -->
        <span>
        </span>
        <el-dropdown @command="handleCommand" class="managerSet" trigger="click">
            <span class="el-dropdown-link" style="color:white;border:none">
                欢迎您！
                <span>管理员</span>
                <i class="el-icon-arrow-down el-icon--right"></i>
            </span>
            <el-dropdown-menu slot="dropdown">
                <el-dropdown-item command="a">个人资料</el-dropdown-item>
                <el-dropdown-item command="e" divided>退出</el-dropdown-item>
            </el-dropdown-menu>
        </el-dropdown>
        <!-- 个人资料对话框 -->
        <el-dialog :visible.sync='dialogVisible' title="个人资料" width="35%" center>
            <el-form :model="formData">
                <el-form-item label="用户名" label-width="70px">
                    <el-input size="mini" v-model="formData.userNickname" :disabled="inputInfo"></el-input>
                </el-form-item>
                <el-form-item label="性别" label-width="70px">
                    <template>
                        <el-radio v-model="radio" :disabled="inputInfo" label="1">男</el-radio>
                        <el-radio v-model="radio" :disabled="inputInfo" label="2">女</el-radio>
                    </template>
                </el-form-item>
                <el-form-item label="移动电话" label-width="70px">
                    <el-input size="mini" v-model="formData.userPhone" :disabled="inputInfo"></el-input>
                </el-form-item>
                <el-form-item label="电子邮箱" label-width="70px">
                    <el-input size="mini" v-model="formData.email" :disabled="inputInfo"></el-input>
                </el-form-item>
            </el-form>
            <span slot="footer" class="dialog-footer">
                <el-button @click="changeInfo" size="small">修 改</el-button>
                <el-button type="primary" :disabled="inputInfo" @click="sureInfo" size="small">保 存</el-button>
            </span>
        </el-dialog>
    </div>
</template>
<script>
import cookie from '../../cookie/index'
import jwtDecode from 'jwt-decode' //解析token
export default {
    data() {
        return {
            dialogVisible:false,
            radio:'',
            inputInfo:true,
            formData:''
        }
    },
    methods: {
      handleCommand(command) {
        // this.$message('click on item ' + command);
        // console.log(jwtDecode(cookie.getToken()));
        if(command === 'a'){
            this.dialogVisible = true
            const value = jwtDecode(cookie.getToken())
            console.log(value);
            this.formData = value
            if(value.sex === '女'){
                console.log(11111);
                this.radio = '2'
            }else{
                this.radio = '1'
            }
        }else{
            this.$confirm('是否确定退出登录?', '提示', {
                confirmButtonText: '确定',
                cancelButtonText: '取消',
                type: 'warning'
            }).then(() => {
                this.$http({
                    url:'/shops/login_and_register/basic/logout',
                    method:'POST',
                    headers:{
                        'Authorization':cookie.getToken()
                    }
                }).then(data => {
                    if(data.data.code === 200){
                        this.$message({
                            type: 'success',
                            message: '退出成功!'
                        });
                        this.$router.push({ name:'login' })
                        cookie.removeToken()
                    }
                }).catch(err => {
                    console.log(err);
                })
            }).catch(() => {
                this.$message({
                    type: 'info',
                    message: '已取消退出'
                });          
            });
        }
      },
      handleMenu(){
          this.$store.commit('collapseMenu')
      },
      changeInfo(){
          this.inputInfo = false
      },
      sureInfo(){
          this.$http({
              url:'/shops/user/update/updateUserBasicMessage',
              method:'GET',
              params:{
                  userId:
              },
              headers:{
                  'Authorization':cookie.getToken()
              }
          })
      }
    },
}
</script>
<style lang="">
    
</style>